package com.yanqu.road.dao.impl.activity.langyabang;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.langyabang.*;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogCrossLangYaBangDaoImpl  extends TempDao {
    public boolean addLogLangYaBangUpgradeBuildingList(List<LogLangYaBangUpgradeBuilding> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCross2Db());
        String sql = "INSERT INTO t_c_lang_ya_upgrade_building_log(activityId,userId,oldAreaLevel,newAreaLevel,coinBefore,costCoin,coinAfter,upgradeJieJiReward,date) VALUES(?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogLangYaBangUpgradeBuilding data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOldAreaLevel()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNewAreaLevel()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getCoinBefore()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getCostCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getCoinAfter()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getUpgradeJieJiReward()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getDate()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogLangYaBangDrawList(List<LogLangYaBangDraw> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCross2Db());
        String sql = "INSERT INTO t_c_lang_ya_draw_log(activityId,userId,oldPower,powerUse,newPower,drawEventId,reward,oldCoin,getCoin,newCoin,building,time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogLangYaBangDraw data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOldPower()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getPowerUse()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNewPower()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getDrawEventId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOldCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getGetCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNewCoin()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBuilding()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogLangYaBangDaiZhengList(List<LogLangYaBangDaiZheng> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCross2Db());
        String sql = "INSERT INTO t_c_lang_ya_dai_zheng_log(activityId,userId,targetUserId,targetBuilding,myBuilding,powerAdd,reward,oldCoin,getCoin,newCoin,date) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogLangYaBangDaiZheng data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTargetUserId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getTargetBuilding()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getMyBuilding()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getPowerAdd()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOldCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getGetCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNewCoin()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getDate()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogLangYaBangPveList(List<LogLangYaBangPve> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCross2Db());
        String sql = "INSERT INTO t_c_lang_ya_pve_log(activityId,userId,npcId,canBattleTime,remainBattleTime,lastNpcBlood,reward,powerAdd,oldCoin,getCoin,newCoin,building,date) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogLangYaBangPve data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNpcId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCanBattleTime()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getRemainBattleTime()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getLastNpcBlood()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getPowerAdd()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOldCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getGetCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNewCoin()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBuilding()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getDate()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogLangYaBangPvpList(List<LogLangYaBangPvp> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCross2Db());
        String sql = "INSERT INTO t_c_lang_ya_pvp_log(activityId,userId,targetUserId,isWin,targetPatrons,targetBuilding,selfPatrons,selfBuilding,declareWarId,powerAdd,reward,oldCoin,getCoin,newCoin,getScore,otherLoseScore,time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogLangYaBangPvp data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTargetUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getIsWin()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getTargetPatrons()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getTargetBuilding()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getSelfPatrons()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getSelfBuilding()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getDeclareWarId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getPowerAdd()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOldCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getGetCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNewCoin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getGetScore()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOtherLoseScore()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

}
